package com.ytjj.qmyx.supplychain.api.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.request.OrderProblemCommitRequest;
import com.ytjj.qmyx.supplychain.common.model.request.OrderProblemListRequest;
import com.ytjj.qmyx.supplychain.common.model.request.OrderProblemReplyRequest;
import com.ytjj.qmyx.supplychain.common.model.response.OrderProblemExportResponse;
import com.ytjj.qmyx.supplychain.common.model.response.OrderProblemListResponse;
import com.ytjj.qmyx.supplychain.service.OrderProblemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/orderProblem")
@RefreshScope
public class OrderProblemController {

    @Resource
    private OrderProblemService orderProblemService;

    /**
     * 提交订单问题
     * @param request
     * @return
     */
    @PostMapping("/commitProblem")
    public CommonResult commitProblem(@RequestBody OrderProblemCommitRequest request) {
        return CommonResult.success(orderProblemService.commitProblem(request));
    }

    /**
     * 回复订单问题
     * @param request
     * @return
     */
    @PostMapping("/replyProblem")
    public CommonResult commitProblem(@RequestBody OrderProblemReplyRequest request) {
        return CommonResult.success(orderProblemService.replyProblem(request));
    }

    /**
     * 订单问题反馈完成
     * @param id
     * @return
     */
    @GetMapping("/finishProblem")
    public CommonResult finishProblem(@RequestParam(value = "id") Integer id) {
        return CommonResult.success(orderProblemService.finishProblem(id));
    }

    /**
     * 修改订单问题的跟单处理状态
     * @param id
     * @return
     */
    @GetMapping("/updateDealStatus")
    public CommonResult updateDealStatus(@RequestParam(value = "id") Integer id,
                                      @RequestParam(value = "dealStatus") Integer dealStatus) {
        return CommonResult.success(orderProblemService.updateDealStatus(id,dealStatus));
    }

    /**
     * 修改问题是否加急
     * @param id
     * @return
     */
    @GetMapping("/updateProblemUrgent")
    public CommonResult updateProblemUrgent(@RequestParam(value = "id") Integer id,
                                         @RequestParam(value = "isUrgent") Integer isUrgent) {
        return CommonResult.success(orderProblemService.updateProblemUrgent(id,isUrgent));
    }

    /**
     * 订单问题列表
     * @param request
     * @return
     */
    @PostMapping("/orderProblemList")
    public CommonPage<OrderProblemListResponse> orderProblemList(@RequestBody OrderProblemListRequest request) {
         return orderProblemService.orderProblemList(request);
    }

    /**
     * 订单问题详情
     * @param id
     * @return
     */
    @GetMapping("/orderProblemDetail")
    public CommonResult orderProblemDetail(@RequestParam Integer id) {
        return CommonResult.success(orderProblemService.orderProblemDetail(id));
    }

    /**
     * 订单问题列表
     * @param request
     * @return
     */
    @PostMapping("/exportOrderProblemList")
    public List<OrderProblemExportResponse> exportOrderProblemList(@RequestBody OrderProblemListRequest request){
        return orderProblemService.exportOrderProblemList(request);
    }
}
